package com.aaa.service.impl;

import com.aaa.dao.ViewTestResultSdsDao;
import com.aaa.entity.ViewTestResultSds;
import com.aaa.service.ViewTestResultSdsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultFpa)表服务实现类
 *
 * @author
 * @since 2022-07-08 10:00:04
 */
@Service("viewTestResultSdsService")
public class ViewTestResultSdsServiceImpl implements ViewTestResultSdsService {
    @Resource
    private ViewTestResultSdsDao viewTestResultSdsDao;

    /**
     * 分页查询
     *
     * @param viewTestResultSds 筛选条件
     * @param pageRequest       分页对象
     * @return 查询结果
     */
    @Override
    public Page<ViewTestResultSds> queryByPage(ViewTestResultSds viewTestResultSds, PageRequest pageRequest) {
        long total = this.viewTestResultSdsDao.count(viewTestResultSds);
        return new PageImpl<>(this.viewTestResultSdsDao.queryAllByLimit(viewTestResultSds, pageRequest), pageRequest, total);
    }

    /**
     * @param viewTestResultSds
     * @return Map
     * @create by: feng (zhaixing@163.com)
     * @description: 根据id查询对应信息
     * @create time: 2022/7/15 15:46
     */
    @Override
    public ViewTestResultSds queryRequestById(ViewTestResultSds viewTestResultSds) {
        ViewTestResultSds Result = this.viewTestResultSdsDao.queryResultSdsById(viewTestResultSds);
        return Result;
    }

    /**
     * @param
     * @return Map<String, Integer>
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有数据
     * @create time: 2022/7/15 16:14
     */
    @Override
    public Map<String, Integer> queryAllPlanSds() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<ViewTestResultSds> viewSdss = this.viewTestResultSdsDao.queryAllPlanSds();
        for (ViewTestResultSds viewSds : viewSdss) {
            double forward = viewSds.getForward();
            double inversion = viewSds.getInversion();
            double sum = (forward + inversion) * 1.25;
            if (sum < 53) {
                normal++;
            } else if (sum < 63) {
                mild++;
            } else if (sum < 73) {
                moderate++;
            } else {
                severe++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("normal", normal);
        map.put("mild", mild);
        map.put("moderate", moderate);
        map.put("severe", severe);
        return map;
    }

    /**
     * @param
     * @return java.util.List<com.aaa.entity.ViewTestResultSds>
     * @create by: feng (zhaixing@163.com)
     * @description:查询所有数据
     * @create time: 2022/7/19 21:06
     */
    @Override
    public List<ViewTestResultSds> queryAllResultSds() {
        List<ViewTestResultSds> viewTestResultSds = this.viewTestResultSdsDao.queryAllResultPlanSds();
        return viewTestResultSds;
    }
    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 删除
     * @create time: 2022/7/22 20:09
     * @param testId
     * @return
     */
    @Override
    public boolean deleteResultById(String testId) {
        Integer integer = this.viewTestResultSdsDao.delResultSds(testId);
        if (integer>0){
            return true;
        }
        return false;
    }

}
